select que_form_no, sum(answer), sum(gum)
from (select que_form_no, count(answer) answer, to_number('0') gum
from research
where coh_no='030' group by que_form_no
union all
select que_form_no, to_number('0') answer, count(gum) gum
from gumsu
where coh_no='030' and gum='2' and gum_date between '20090101' and '20090130'
group by que_form_no, to_char(0,'99'))
group by que_form_no
order by que_form_no;
3. Execution Plan
Execution Plan
----------------------------------------------------------
Plan hash value: 739072605
--------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost(%CPU)| Time |
--------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 35 | 1155 | 38976 (1)| 00:07:48 |
| 1 | SORT GROUP BY | | 35 | 1155 | 38976 (1)| 00:07:48 |
| 2 | VIEW | | 35 | 1155 | 38975 (1)| 00:07:48 |
| 3 | UNION-ALL | | | | | |
| 4 | SORT GROUP BY NOSORT | | 34 | 340 | 38297 (1)| 00:07:40 |
| 5 | TABLE ACCESS BY INDEX ROWID| RESEARCH | 38392 | 374K| 38297 (1)| 00:07:40 |
|* 6 | INDEX RANGE SCAN | INDEX_RESEARCH | 38392 | | 243 (1)| 00:00:03 |
| 7 | HASH GROUP BY | | 1 | 15 | 677 (1)| 00:00:09 |
|* 8 | TABLE ACCESS BY INDEX ROWID| GUMSU | 1 | 15 | 676 (0)| 00:00:09 |
|* 9 | INDEX RANGE SCAN | GUMSU_S_PK | 1950 | | 19 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
6 - access("COH_NO"='030')
filter("COH_NO"='030')
8 - filter("GUM_DATE">=20090101 AND "GUM"='2' AND "GUM_DATE"<=20090130)
9 - access("COH_NO"='030')
1. Query
select que_form_no, sum(answer), sum(gum)
from (select que_form_no, count(answer) answer, to_number('0') gum
from research
where coh_no='030' group by que_form_no
union all
select que_form_no, to_number('0') answer, count(gum) gum
from gumsu
where coh_no='030' and gum='2' and gum_date between '20090101' and '20090130'
group by que_form_no, to_number('0'))
group by que_form_no
order by que_form_no;
Execution Plan
----------------------------------------------------------
Plan hash value: 2616170847
--------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost(%CPU)| Time |
--------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 35 | 1155 | 38975 (1)| 00:07:48 |
| 1 | SORT GROUP BY | | 35 | 1155 | 38975 (1)| 00:07:48 |
| 2 | VIEW | | 35 | 1155 | 38974 (1)| 00:07:48 |
| 3 | UNION-ALL | | | | | |
| 4 | SORT GROUP BY NOSORT | | 34 | 340 | 38297 (1)| 00:07:40 |
| 5 | TABLE ACCESS BY INDEX ROWID| RESEARCH | 38392 | 374K| 38297 (1)| 00:07:40 |
|* 6 | INDEX RANGE SCAN | INDEX_RESEARCH | 38392 | | 243 (1)| 00:00:03 |
| 7 | SORT GROUP BY NOSORT | | 1 | 15 | 676 (0)| 00:00:09 |
|* 8 | TABLE ACCESS BY INDEX ROWID| GUMSU | 1 | 15 | 676 (0)| 00:00:09 |
|* 9 | INDEX RANGE SCAN | GUMSU_S_PK | 1950 | | 19 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
6 - access("COH_NO"='030')
filter("COH_NO"='030')
8 - filter("GUM_DATE">=20090101 AND "GUM"='2' AND "GUM_DATE"<=20090130)
9 - access("COH_NO"='030')
filter("COH_NO"='030')